<?php
	if ($act == 'registation') {	
		$w_type = validate_captcha();
		if($w_type == ''){
			$array_data = array();
			foreach($_POST as $key=>$el){
				if ((strpos($key, "form_data_") !== false) and (strpos($key, "form_data_") == 0)) $array_data[$key] = $el;
				elseif ((strpos($key, "form_login_data_") !== false) and (strpos($key, "form_login_data_") == 0)) $array_login_data[$key] = $el;
			}
			if (isset($_POST["form_id"]) && (strlen($_POST["form_id"]) > 0)){
				if (isset($array_login_data['form_login_data_']['login']) && (strlen($array_login_data['form_login_data_']['login']) > 0) && isset($array_login_data['form_login_data_']['pass1']) && (strlen($array_login_data['form_login_data_']['pass1']) > 0)){
					if (!ereg("[^a-zA-Z0-9_-]", $array_login_data['form_login_data_']['login'])){
						if (isset($array_login_data['form_login_data_']['pass1']) && isset($array_login_data['form_login_data_']['pass2']) && ($array_login_data['form_login_data_']['pass1']==$array_login_data['form_login_data_']['pass2'])){
							$res = 0;
							
							$array_login_data['form_login_data_']['login'] = trim($array_login_data['form_login_data_']['login']);
							$sql = $mysqlclass->mysql_my_query("SELECT `id` FROM `".$setupdata['table_prefix']."client_data` WHERE `name`='id_login' AND `value`='".$array_login_data['form_login_data_']['login']."'", __LINE__, __FILE__);
							if (mysql_num_rows($sql) > 0) $res = 6;

							$array_login_data['form_login_data_']['email'] = strtolower(trim($array_login_data['form_login_data_']['email']));
							$sql = $mysqlclass->mysql_my_query("SELECT `id` FROM `".$setupdata['table_prefix']."client` WHERE `email`='".$array_login_data['form_login_data_']['email']."'", __LINE__, __FILE__);
							if (mysql_num_rows($sql) > 0) $res = 14;
							
							if ($res == 0){
								$res = $clientsclass->add_new_registation($array_login_data['form_login_data_'], $array_data, 0, $_POST["form_id"]);
							}
							if ($res != 0) $err->AddError($res, "clients");
						} else $err->AddError(3, "clients");
					} else $err->AddError(25, "clients");
				} else {
					//$err->AddError(20, "clients");
					$array_login_data['form_login_data_']['email'] = strtolower(trim($array_login_data['form_login_data_']['email']));
					$sql = $mysqlclass->mysql_my_query("SELECT `id` FROM `".$setupdata['table_prefix']."client` WHERE `email`='".$array_login_data['form_login_data_']['email']."'", __LINE__, __FILE__);
					if (mysql_num_rows($sql) > 0) $res = 14;
					if ($res != 0) $err->AddError($res, "clients");
							
					$res = $clientsclass->add_new_registation($array_login_data['form_login_data_'], $array_data, 1, $_POST["form_id"]);
					if ($res != 0) $err->AddError($res, "clients");
				}
			} else $err->AddError(15, "clients");
		}// else $err->AddError(36, "clients");
	} elseif ($act == 'mod_info') {
		$client_data = array();
		if (isset($_POST["client_id"]) && (strlen($_POST["client_id"]) > 0)){
			foreach($_POST as $key=>$el){
				if ((strpos($key, "form_data_") !== false) and (strpos($key, "form_data_") == 0)){
					$key = substr($key, strlen("form_data_"));
					$client_data[$key] = $el;
				}
			}
			$res = $clientsclass->mod_user_registation_data($_POST["client_id"], $client_data);
			if ($res != 1) $err->AddError($res, "clients");
		}
	} elseif ($act == 'pass_step1') {
		if (!isset($_GET['email'])) $email=NULL; else $email=$_GET['email'];
		if ($email==NULL) if (!isset($_POST['email'])) $email=NULL; else $email=$_POST['email'];
		if ($email != NULL) {
			if (eregi("^[a-z0-9]+([-_\.]?[a-z0-9])+@[a-z0-9]+([-_\.]?[a-z0-9])+\.[a-z]{2,4}", $email)){
				$res = $clientsclass->user_pass_remind($email, 'step1');
				if ($res != 0) $err->AddError($res, "clients");
			} else $err->AddError(13, "clients");
		} else $err->AddError(13, "clients");
	} elseif ($act == 'pass_step2') {
		if (!isset($_GET['email'])) $email=NULL; else $email=$_GET['email'];
		if (!isset($_GET['confirm'])) $confirm=NULL; else $confirm=$_GET['confirm'];
		if (($email != NULL) && ($confirm != NULL)) {
			if (eregi("^[a-z0-9]+([-_\.]?[a-z0-9])+@[a-z0-9]+([-_\.]?[a-z0-9])+\.[a-z]{2,4}", $email)){
				if (strlen($confirm) == 32){
					$clientsclass->user_pass_remind($email, 'step2', $confirm);
				}
			} else $err->AddError(13, "clients");
		}
	} 
?>
